package demo.response;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
// 获取多选框数据
import java.io.IOException;
@WebServlet(name = "RequestParamsServlet", urlPatterns = "/RequestParamsServlet")
public class RequestParamsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println("用户名:" + name);
        System.out.println("密  码:" + password);
        if ("itcast".equals(name) && "123".equals(password)){
            resp.sendRedirect("/welcome_a.html");
        }else {
            resp.sendRedirect("/login_a.html");
        }
        String[] hobbys = req.getParameterValues("hobby");
        System.out.println("爱好:");
        for (int i = 0; i < hobbys.length; i++) {
            System.out.print(hobbys[i] + ", ");
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
